package com.lg.erp.controller.chenkang;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lg.erp.entity.JsonResult;
import com.lg.erp.entity.chenkang.TCargoArea;
import com.lg.erp.service.chenkang.ICargoAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.List;
import java.util.UUID;

@RestController
public class CargoAreaController {

    @Autowired
    private ICargoAreaService cargoAreaService;

    //通过库区id来查询所属仓库
    @RequestMapping("/cargoAreaGoodsNo")
    public JsonResult selectGoodsNoByWare(){
        List<TCargoArea> tCargoAreas = cargoAreaService.selectWareByCargoNO();
        return new JsonResult(1,"查询成功",tCargoAreas);
    }

    //分页(模糊查询)
    @RequestMapping("/cargoArea")
    public JsonResult pageCargoArea(@RequestParam(value = "current",required = false,defaultValue = "1")
                                                Integer current,String wareName,String goodsName,String dateTime){
        Page<TCargoArea> page=new Page<>(current,10);
        IPage<TCargoArea> pages=cargoAreaService.pageCargoArea(page,wareName,goodsName,dateTime);
        System.out.println("pages的值"+pages);
        return new JsonResult(1,"ok",pages);

    }


    //增加
    @PostMapping("/cargoArea")
    public JsonResult saveCargoArea(@RequestBody TCargoArea cargoArea){
        cargoArea.setId(UUID.randomUUID().toString().substring(0,7));
        cargoArea.setDeteTime1(new Timestamp(System.currentTimeMillis()));
        cargoAreaService.save(cargoArea);
        return new JsonResult(1,"创建成功",cargoArea);
    }
    //修改
    @PutMapping("/cargoArea")
    public JsonResult updateCargoArea(@RequestBody TCargoArea cargoArea){
        cargoAreaService.updateById(cargoArea);
        return new JsonResult(1,"更新成功",cargoArea);

    }
    @RequestMapping(value = "/cargoArea/{id}",method = RequestMethod.DELETE)
    public JsonResult removeCargoArea(@PathVariable("id") String id){
        cargoAreaService.removeById(id);
        return new JsonResult(1,"删除成功",id);
    }
}
